package com.example.black.myapplication;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.black.myapplication.androidframwork.MainTonchEventActivity;
import com.example.black.myapplication.androidframwork.MyViewPagerActivity;
import com.example.black.myapplication.canvas.CanvasActivity;
import com.example.black.myapplication.dragswip.GragSwipActivity;
import com.example.black.myapplication.filtercolorrgb.FilterActivity;
import com.example.black.myapplication.materia.DrawLayoutDemoActivity;
import com.example.black.myapplication.materia.TabLayoutDemoActivity;
import com.example.black.myapplication.materia.TextInputLayoutActivity;
import com.example.black.myapplication.mynet.WeatherActivity;
import com.example.black.myapplication.myrevealview.RevealViewActivity;
import com.example.black.myapplication.myrevealview.ViolationListArrowDrawable;
import com.example.black.myapplication.objectanimator.ObjectAnimatorActivity;
import com.example.black.myapplication.paintlearn.PaintViewActivity;
import com.example.black.myapplication.pathlearn.PathActivity;
import com.example.black.myapplication.shader.ShaderActivity;
import com.example.black.myapplication.wrap.WrapViewActivity;

public class MainActivity extends AppCompatActivity {

    private Button clear;
    private Button rv;
    private Button rvHeader;
    private Button btnDrawer;

    private int SETTINGS_ACTION = 1;
    private Button btnInput;
    private Button btnPager;
    private Button btnTestListener;
    private Button btnTouch;
    private Button btnPaint;
    private Button btnMyViewpager;
    private Context context;
    private Button btnShader;
    private Button btnFilter;
    private Button btnCanvas;
    private Button btnReveal;
    private Button btnPath;
    private Button btnUiFlow;
    private Button btnObjectAnimator;
    private ImageView tvTest;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setTheme(DemoApplication.getStyle());
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        context = this;
    }

    public void setBtnPath(Button btnPath) {
        this.btnPath = btnPath;
    }

    private void initView() {
        tvTest =  findViewById(R.id.tv_test);
        tvTest.setImageDrawable(new ViolationListArrowDrawable());
        btnDrawer = findViewById(R.id.btn_drawer);
        clear = findViewById(R.id.clear);
        rv = findViewById(R.id.recyclerView);
        rvHeader = findViewById(R.id.rvHeader);
        btnDrawer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(
                        MainActivity.this
                        , DrawLayoutDemoActivity.class
                ));
            }
        });
        rvHeader.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(
                        MainActivity.this
                        , WrapViewActivity.class
                ));
            }
        });
        rv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(
                        MainActivity.this
                        , GragSwipActivity.class
                ));
            }
        });
        clear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivityForResult(new Intent(MainActivity.this,
                        MDActivity.class), SETTINGS_ACTION);
            }
        });

        btnInput = findViewById(R.id.btn_input);
        btnInput.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(
                        MainActivity.this
                        , TextInputLayoutActivity.class
                ));
            }
        });
        btnPager = findViewById(R.id.btn_pager);
        btnPager.setOnClickListener(v -> startActivity(new Intent(
                MainActivity.this
                , TabLayoutDemoActivity.class
        )));
        btnTestListener = findViewById(R.id.btn_test_listener);
        btnTestListener.setOnClickListener(v -> Toast.makeText(
                MainActivity.this
                , "测试一下"
                , Toast.LENGTH_LONG
        ).show());
        btnTouch = findViewById(R.id.btn_touch);
        btnTouch.setOnClickListener(v -> startActivity(new Intent(
                MainActivity.this
                , MainTonchEventActivity.class
        )));
        btnPaint = (Button) findViewById(R.id.btn_paint);
        btnPaint.setOnClickListener(v -> {
            startActivity(new Intent(context, PaintViewActivity.class));
        });
        btnMyViewpager = findViewById(R.id.btn_my_view_pager);
        btnMyViewpager.setOnClickListener(v -> {
            startActivity(new Intent(context, MyViewPagerActivity.class));
        });
        btnShader = (Button) findViewById(R.id.btn_shader);
        btnShader.setOnClickListener(v -> {
            startActivity(new Intent(context, ShaderActivity.class));
        });
        btnFilter = (Button) findViewById(R.id.btn_filter);
        btnFilter.setOnClickListener(v -> {
            startActivity(new Intent(context, FilterActivity.class));
        });

        btnCanvas = (Button) findViewById(R.id.btn_canvas);
        btnCanvas.setOnClickListener(v -> {
            startActivity(new Intent(context, CanvasActivity.class));
        });

        btnReveal = (Button) findViewById(R.id.btn_reveal);
        btnReveal.setOnClickListener(v -> {
            startActivity(new Intent(
                    context
                    , RevealViewActivity.class
            ));
        });

        btnPath = (Button) findViewById(R.id.btn_path);
        btnPath.setOnClickListener(v -> {
            startActivity(
                    new Intent(
                            context
                            , PathActivity.class
                    )
            );
        });

        btnUiFlow = (Button) findViewById(R.id.btn_ui_flow);
        btnUiFlow.setOnClickListener(v -> {
            startActivity(
                    new Intent(
                            context
                            , WeatherActivity.class
                    )
            );
        });
        btnObjectAnimator = (Button) findViewById(R.id.btn_object_animator);
        btnObjectAnimator.setOnClickListener(v -> {
            startActivity(
                    new Intent(
                            context
                            , ObjectAnimatorActivity.class
                    )
            );
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == SETTINGS_ACTION && resultCode == RESULT_OK) {
            finish();
            Intent intent = getIntent();
            startActivity(intent);
        }
    }
}
